from sqlalchemy.dialects.mysql import TEXT

from app import db
from .base_model import BaseModel


class LoginLog(BaseModel):
    '''登录日志'''
    __tablename__ = 'user_login_log'
    __table_args__ = ({'comment': '用户登录日志'})
    id = db.Column(db.Integer, primary_key=True, comment="记录ID")
    user_id = db.Column(db.Integer, db.ForeignKey('blog_user.id'), nullable=False, comment="登录用户ID")
    ip = db.Column(db.String(255), nullable=False, comment="登录ip")
    ip_address = db.Column(db.String(255), nullable=False, comment="登录ip归属")
    source = db.Column(db.String(255), nullable=False, comment="登录来源")
    user_agent = db.Column(TEXT, nullable=False, comment="登录UA")

    def __repr__(self) -> str:
        return "<LoginLog %s>" % self.to_json()
